package cars;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Users {
    Scanner sc = new Scanner(System.in);//输入流
    private String UserID;//账号
    private String UserPWD;//密码
    private String UserName;//用户身份

    public Users() {
    }

    //无参
    public Users(String userID, String userPWD, String userName) {
        UserID = userID;
        UserPWD = userPWD;
        UserName = userName;
    }

    //有参
    public String toString() {
        return UserID + "-" + UserPWD + "-" + UserName;
    }

    //返回用户
    public String getUserID() {
        return UserID;
    }

    //获得账号
    public void setUserID(String userID) {
        UserID = userID;
    }

    //设置账号
    public String getUserPWD() {
        return UserPWD;
    }

    //获得密码
    public void setUserPWD(String userPWD) {
        UserPWD = userPWD;
    }

    //设置密码
    public String getUserName() {
        return UserName;
    }

    //获取身份
    public void setUserName(String userName) {
        UserName = userName;
    }

    //设置身份
    public void authority(ArrayList<Vehicle> list, ArrayList<Users> users) throws IOException {
        if (this.UserName.equals("顾客")) {
            //当判断为顾客时，进行顾客端操作
            Customers C = (Customers) this;
            //强转为顾客类
            System.out.println("您当前剩余" + C.getMoney() + "元");
            if (C.getIdentity().equalsIgnoreCase("vip")) {
                //当判断是vip时
                System.out.println("vip顾客登陆成功！！！");
                while (true) {
                    System.out.println("1.查看车辆 2.租车 3.换车 4.返回");
                    System.out.print("请选择：");
                    String chooseCase1 = sc.next();
                    switch (chooseCase1) {
                        case "1" -> C.ViewCar(list);//查看汽车
                        case "2" -> C.RentCar(list, users);//租车
                        case "3" -> C.ChangeCar(list, users);//换车
                        case "4" -> {//退出
                            return;
                        }
                        default -> System.out.println("没有该选项，请重新输入");
                    }
                }
            } else {
                System.out.println("普通用户登陆成功！！！");
                //普通用户
                while (true) {
                    System.out.println("1.查看车辆 2.充值会员 3.退出");
                    System.out.print("请选择：");
                    String chooseCase1 = sc.next();
                    switch (chooseCase1) {
                        case "1" -> C.ViewCar(list);//查看
                        case "2" -> C.AddVIP(list, users);//成为会员
                        case "3" -> {
                            return;//退出
                        }
                        default -> System.out.println("没有该选项，请重新输入");
                    }
                }
            }
        } else if (this.UserName.equals("管理员")) {
            //管理员
            Administrators A = (Administrators) this;
            System.out.println("管理员登录成功!!");
            while (true) {
                System.out.println("1.查看车辆 2.添加车辆 3.删除车辆 4.修改车辆 5.顾客充值 6.查看营业额 7.返回");
                System.out.print("请选择：");
                String chooseCase1 = sc.next();
                switch (chooseCase1) {
                    case "1":
                        A.ViewCar(list);//查看车辆
                        break;
                    case "2":
                        A.AddCar(list, users);//添加车辆
                        break;
                    case "3":
                        A.QueueCar(list, users);//删除车辆
                        break;
                    case "4":
                        A.ChangeCar(list, users);//修改车辆
                        break;
                    case "5":
                        A.AddMoney(users, list);//顾客充值
                        break;
                    case "6":
                        A.ViewMoney();//查看营业额
                        break;
                    case "7":
                        return;//返回
                    default:
                        System.out.println("没有该选项，请重新输入");
                }
            }
        } else {
            System.out.println("非法用户，请重新输入");
        }
    }
}
